export const state = () => ({
  list: [],
  token: ''
})


export const actions = {
  nuxtServerInit({
    commit
  }, {
    req
  }) {
    let cookie = req.headers.cookie;
    // 将cookie转成json对象（自己实现该方法）
    let token = cookieparse(cookie).token;
    commit('setToken', token);
  },
}

export const mutations = {
  setToken(state, token) {
    state.token = token
  },
  add(state, text) {
    state.list.push({
      text: text,
      done: false
    })
  },
  remove(state, {
    todo
  }) {
    state.list.splice(state.list.indexOf(todo), 1)
  },
  toggle(state, todo) {
    todo.done = !todo.done
  }
}
